To integrate Identigo with your server you will need a few endpoints setup so that the cookie exchance can happen from your app server.
When the user logs in through the Identigo login page, the Identigo server sends back a cookie for if the user hits that page again for any of their registered apps, and will log them in automatically. But you will also need to have a cookie thats been issued by your app server. This is where the exchance come in.
The following example is done in NestJs but its very similar elsewhere.
import { Body, Controller, Get, Post, Req, Res } from "@nestjs/common";
import { CookieOptions, Request, Response } from "express";
import { AuthService } from "src/core/services/auth/auth.service";
@Controller("auth")
export class AuthController {
constructor(private authService: AuthService) {}
@Post("exchange")
async exchange(
@Req() req: Request,
@Res() res: Response,
@Body() body: { requestToken: string; email: string; appId: string }
) {
try {
const { token, cookieOptions } = await this.authService.exchange(body.requestToken, body.email, body.appId);
cookieOptions.domain = "";
res.cookie("token", token, cookieOptions as CookieOptions);
res.send({ access_token: token });
} catch (err: any) {
res.status(400).send({ message: err.message });
}
}
@Get("check-token")
async checkToken(@Req() req: Request, @Res() res: Response) {
const token = req.cookies.token;
const verify = await this.authService.verifyToken(token);
if (!verify) {
res.send({ access_token: null });
// res.status(401).send({ message: "Unauthorized" });
return;
}
res.send({ access_token: token });
return;
}
}
As you can see, the Identigo SDK does all the heavy lifting, all you need to do is set the cookie and return the access_token. If you don't want to use cookies and only use the access token from local storage, you can do that if you like.
These endpoints have to be exactly as specified here, but you can have them on any route of your choosing, as that will be set in the frontend SDK as the exchangeUrl.
Powered by Doctave